-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: replace channel with callback of transport in swarm #561
Conversation
ad7ec31
to
243601f
Compare
77aa542
to
d3958f7
Compare
plz avoid exposing swarm components such as: ➜ core git:(ma_channel) ✗ pcregrep -rM 'swarm.transport(\n)?.*' src
src/swarm/builder.rs: /// Sets up the external address for swarm transport.
src/dht/stabilization.rs: let conns = self.swarm.transport.get_connections();
src/dht/stabilization.rs: self.swarm.transport.session_sk(),
src/dht/stabilization.rs: self.swarm.transport.send_payload(payload).await?;
src/dht/stabilization.rs: self.swarm.transport.session_sk(),
src/dht/stabilization.rs: self.swarm.transport.send_payload(payload).await?;
src/tests/default/test_connection.rs: assert!(node1.swarm.transport.get_connection(node2.did()).is_none());
src/tests/default/test_connection.rs: assert!(node2.swarm.transport.get_connection(node1.did()).is_none());
src/tests/default/mod.rs: self.swarm.transport.get_connection_ids(),
src/tests/default/mod.rs: self.swarm.transport.get_connections().len(),
src/tests/default/mod.rs: assert!(self.swarm.transport.get_connection(addr).is_some());
src/tests/default/test_message_handler.rs: let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs: let connection_2_to_3 = node2.swarm.transport.get_connection(node3.did()).unwrap();
src/tests/default/test_message_handler.rs: let connection_1_to_3 = node1.swarm.transport.get_connection(node3.did());
src/tests/default/test_message_handler.rs: let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs: let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs: let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/tests/default/test_message_handler.rs: let connection_1_to_2 = node1.swarm.transport.get_connection(node2.did()).unwrap();
src/message/handlers/connection.rs: assert!(node1.swarm.transport.get_connection(node3.did()).is_none());
src/message/handlers/connection.rs: assert!(node1.swarm.transport.get_connection(node3.did()).is_none());
src/message/handlers/connection.rs: if let Some(t) = node2.swarm.transport.get_connection(node1.did()) {
src/inspect.rs: let connections = swarm.transport.get_connections(); just hide or wrap the transport, and call functions as swam.get_connections |
|
||
for (did, conn) in conns.into_iter() { | ||
if conn.is_disconnected().await { | ||
if matches!( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I dont think match WebrtcConnectionState
here is a good idea.
The keyword WebRTC
and belonged details is not necessary to be known for swarm / DHT layer.
Just is_connected / is_pending / is_disconnected is fine here
crates/core/src/dht/stabilization.rs
Outdated
@@ -88,11 +92,11 @@ impl Stabilization { | |||
tracing::debug!("STABILIZATION notify_predecessor: {:?}", s); | |||
let payload = MessagePayload::new_send( | |||
msg.clone(), | |||
self.swarm.session_sk(), | |||
self.swarm.transport.session_sk(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the difference between swarm.session_sk
and swarm.transport.session_sk
?
s, | ||
self.swarm.did(), | ||
)?; | ||
self.swarm.send_payload(payload).await?; | ||
self.swarm.transport.send_payload(payload).await?; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Dont expose transport, just wrap it.
|
||
if payload.transaction.destination == self.did { | ||
if payload.transaction.destination == self.transport.dht.did { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transport.dht.did?
swarm.did()?
swarm.dht.did?
crates/core/src/swarm/mod.rs
Outdated
message_handler: MessageHandler, | ||
transport: BoxedTransport<ConnectionOwner, TransportError>, | ||
/// Swarm tansport. | ||
pub transport: Arc<SwarmTransport>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the SwarmTransport is actually TransportWithDHT
pub struct SwarmTransport {
transport: Transport,
session_sk: SessionSk,
pub(crate) dht: Arc<PeerRing>,
#[allow(dead_code)]
measure: Option<MeasureImpl>,
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe just rename SwarmTransport
to ConnectionManager
is better.
The word Transport
Connection
, and the way we call them are making confuse here.
Just a metaphor, Transport is a train, Connection is a railway. getting railwayS from a train via the railway station is making no sense.
Please check if the PR fulfills these requirements
🔵 What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)
🟤 What is the current behavior? (You can also link to an open issue here)
🟢 What is the new behavior (if this is a feature change)?
☢️ Does this PR introduce a breaking change? (What changes might users need to make in their application due to this PR?)
ℹ️ Other information
Closes #issue